package fr.inserm.u915.tabixserver;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Model
	{
	private List<Table> tables=new ArrayList<Table>();
	/*private List<Instance> instances=new ArrayList<Instance>();
	private Map<String, Instance> id2instance=new HashMap<String, Instance>();*/
	private List<Build> builds=new ArrayList<Build>();
	private Map<String, Build> id2build=new HashMap<String, Build>();
	private Map<String,User> id2user=new HashMap<String, User>();
	private Map<String,Group> id2group=new HashMap<String, Group>();
	
	public List<Table> getTables()
		{
		return tables;
		}
	
	/*public List<Instance> getInstances()
		{
		return instances;
		}*/
	public List<Build> getBuilds()
		{
		return builds;
		}
	/*
	public Instance getInstanceById(String id)
		{
		return id2instance.get(id);
		}
	void putInstance(Instance instance)
		{
		this.id2instance.put(instance.getId(), instance);
		this.instances.add(instance);
		}*/

	
	public Build getBuildById(String id)
		{
		return id2build.get(id);
		}
	void putBuild(Build b)
		{
		this.id2build.put(b.getId(), b);
		this.builds.add(b);
		}
	
	void putUser(User u)
		{
		this.id2user.put(u.getLogin(),u);
		}
	
	void putGroup(Group g)
		{
		this.id2group.put(g.getId(),g);
		}
	
	/*
	public List<Instance> getInstancesByBuild(Build b)
		{
		List<Instance> L=new ArrayList<Instance>();
		for(Instance i:getInstances())
			{
			if(i.getBuild()==b) L.add(i);
			}
		return L;
		}*/
	
	public User getUserById(String id)
		{
		return id2user.get(id);
		}
	
	public Group getGroupById(String id)
		{
		if(id==null || id.isEmpty() || id.equals("*")) return Group.getDefaultGroup();
		return this.id2group.get(id);
		}
	
	
	}
